<%-- 
    Document   : exportFile
    Created on : 06.12.2011, 22:03:32
    Author     : Николай
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ page errorPage = "Error.jsp" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
<%@ page import="java.io.*" %>
<%
    if (request.getSession().getAttribute("xmlPath") != null) {

        String filename = (String) request.getSession().getAttribute("xmlPath");
        response.setHeader("Content-Type", "application/octet-stream;");
        String shortname = filename.substring(filename.lastIndexOf("\\") + 1,
                filename.length());
        response.setHeader("Content-Disposition",
                "filename=\"" + shortname + "\"");
        BufferedInputStream in = new BufferedInputStream(
                new FileInputStream(filename));
        BufferedOutputStream binout = new BufferedOutputStream(
                response.getOutputStream());
        int ch = in.read();
        while (ch != -1) {
            binout.write(ch);
            ch = in.read();
        }
        binout.close();
        in.close();
    } else {
        
        throw new FileNotFoundException("File isn't generated");
    }
%>